import sys

CLASS = sys.argv[1]

gold_ = open('features/development' + str(CLASS) + '.dat')
gold = gold_.readlines()
gold_.close()

answers_ = open('svm_perf/output' + str(CLASS))
answers = answers_.readlines()
answers_.close()

raw_ = open('features/development' + str(CLASS) + '.features')
raw = raw_.readlines()
raw_.close()

error_FP = open('error_FP' + str(CLASS), 'w')
error_FN = open('error_FN' + str(CLASS), 'w')

TP = FP = TN = FN = 0

for i in range(len(gold)):
    #print gold[i][0], answers[i].strip()
    
    pred = eval(answers[i].strip())
    if gold[i][0] == '1' and pred > 0:
        TP += 1
    elif gold[i][0] == '0' and pred > 0:
        FP += 1
        error_FP.write(raw[i])
    elif gold[i][0] == '1' and pred <= 0:
        FN += 1
        error_FN.write(raw[i])
    elif gold[i][0] == '0' and pred <= 0:
        TN += 1


error_FP.close()
error_FN.close()

print "FN \t", FN
print "FP \t", FP
print "TN \t", TN
print "TP \t", TP

print "all positive \t", TP + FN
print "all negative \t", TN + FP

P = 1.0 * TP / (TP + FP)
R = 1.0 * TP / (TP + FN)
print "Precision \t= \t" + str(P)
print "Recall \t\t= \t" + str(R)
print "F-Score \t= \t" + str(2 * P * R / (P + R))
print
print "Specificity \t= \t" + str(1.0* TN / (TN + FP))
